import http from "../index";

// 分页获取会员
export const getUsers = ({
    ascended = null,
    current = null,
    size = null,
    sortFieldName = null,
    status = null,
    nickName = null,
    outletsSid = null,
    phone = null,
    sex = null,
}) => {
    return http.get("users", {
        ascended,
        current,
        size,
        sortFieldName,
        status,
        nickName,
        outletsSid,
        phone,
        sex,
    });
};

// 根据sid获取会员
export const getUserDetail = ({ sid }) => {
    return http.get("users/" + sid);
};

// 新增会员
export const addUser = ({
    phone,
    password,
    avatar = null,
    birth = null,
    email = null,
    nickName = null,
    note = null,
    outletsSid = null,
    roleSids = null,
    sex = null,
    status = null,
    userName = null,
}) => {
    return http.post("users", {
        phone,
        password,
        avatar,
        birth,
        email,
        nickName,
        note,
        outletsSid,
        roleSids,
        sex,
        status,
        userName,
    });
};

// 修改会员
export const editUser = ({
    sid,
    phone = null,
    avatar = null,
    birth = null,
    email = null,
    nickName = null,
    note = null,
    outletsSid = null,
    roleSids = null,
    sex = null,
    status = null,
    userName = null,
}) => {
    return http.put("users/" + sid, {
        phone,
        avatar,
        birth,
        email,
        nickName,
        note,
        outletsSid,
        roleSids,
        sex,
        status,
        userName,
    });
};

// 批量删除会员
export const delUsers = ({ sidList }) => {
    return http.put("users/delete", { sidList });
};

// 导出会员
export const exportUser = ({
    ascended = null,
    current = null,
    size = null,
    sortFieldName = null,
    status = null,
    userName = null,
    outletsSid = null,
    phone = null,
    sex = null,
}) => {
    return http.get("users/export", {
        ascended,
        current,
        size,
        sortFieldName,
        status,
        userName,
        outletsSid,
        phone,
        sex,
    });
};

// 根据sid启用-停用会员
export const changeUserStatus = ({ sid }) => {
    return http.put("users/" + sid + "/status");
};

// 分页获取用户下单能使用的优惠卷(代客下单使用)
export const getUserCoupons = ({
    userSid,
    ascended = null,
    current = null,
    size = null,
    sortFieldName = null,
    state,
}) => {
    return http.get("user-coupons/" + userSid + "/order-coupons", {
        state,
        ascended,
        current,
        size,
        sortFieldName,
    });
};

// 分页获取提货员
export const getTakePickers = ({
    ascended = null,
    current = null,
    size = null,
    sortFieldName = null,
    phone = null,
    userName = null,
}) => {
    return http.get("users/take-picker", {
        ascended,
        current,
        size,
        sortFieldName,
        phone,
        userName,
    });
};

// 分页获取取货员
export const getPickers = ({
    ascended = null,
    current = null,
    size = null,
    sortFieldName = null,
    phone = null,
    userName = null,
}) => {
    return http.get("users/picker", {
        ascended,
        current,
        size,
        sortFieldName,
        phone,
        userName,
    });
};

// 分页获取员工
export const getStaffs = ({
    ascended = null,
    current = null,
    size = null,
    sortFieldName = null,
    status = null,
    nickName = null,
    roleKey = null,
    phone = null,
}) => {
    return http.get("users/users", {
        ascended,
        current,
        size,
        sortFieldName,
        status,
        nickName,
        roleKey,
        phone,
    });
};

// 修改用户密码
export const changeUserPassword = ({ sid, password }) => {
    return http.put("users/" + sid + "/pas", { password });
};

// 修改当前登录账号密码
export const changeCurAccountPwd = ({ oldPassword, newPassword }) => {
    return http.put("users/pas-me", { oldPassword, newPassword });
};

// 修改员工出勤状态
export const changeStaffWorkStatus = ({ sid }) => {
    return http.put("users/work-status", { sid });
};

// 注销员工
export const logoutStaff = ({ sid }) => {
    return http.get("users/" + sid + "/logout");
};
